<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_default
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<div class="reviews-content-box">
<div class="head">
    <h4><?php echo $this->__('Write Your Own Review') ?></h4>
</div>
<div class="reviews-content">
  <div class="bag-en"></div>
  <div>
  <p><?php echo $this->__("You're reviewing: %s", $this->htmlEscape($this->getProductInfo()->getName())) ?></p>
  <p>Tell us what you think about this item and share your opinions with other people. Please make sure your review focuses only on this item. All reviews are moderated and will be reviewed within two business days. Inappropriate reviews will not be posted.</p>
  <p><strong>After-sales questions and issues</strong>: Contact our	<a target="_blank" class="red u" href="<?php echo $this->getUrl('contacts');?>">
		Customer Service Department</a>.
	(A customer representative will get back to you).
  </p>
  <p>Please	<a class="red u" href="<?php echo $this->getUrl('customer/account/login/');?>">Login</a>
	first if you want to later edit or manage reviews uploaded by yourself.
  </p>
  </div>
  <form action="<?php echo $this->getAction() ?>" enctype="multipart/form-data" method="post" id="review-form" >
  <script type="text/javascript">
  var langs="en";
  var cssPrefix="http://i1.lbox.me/css/";
  var jsPrefix="http://i1.lbox.me/js/";
  var imgPrefix="";
  var swfPrefix="http://i1.lbox.me/swf/";
  var baseURL="http://www.lightinthebox.com/";
  var FRIENDLY_URLS = 'true';
  </script>
  <script type="text/javascript">
  var BvGlobalCounter=function(){};BvGlobalCounter.value=0;function bvGetMouseX(e){var tempX;if(document.all){tempX=e.clientX+document.body.scrollLeft;}else{tempX=e.pageX;}if(tempX<0){tempX=0;}return tempX;}

  function BvRatingBar(ratedItem){
    var $ = jQuery;
  	var _prepend=ratedItem;
  	var _BGWidth=15;
  	var _BGHeight=14;
  	var _specificity=1;
  	var _maxRating=5;
  	var _minRating=1;
  	var _ratingType="Stars";
  	var _ratingTypeSingular="Star";
  	var _sparkleImage="<?php echo $this->getSkinUrl('images/sparkle.gif');?>";
  	var _rating;
  	var _displayItemOverride=_prepend+"score_title";
  	var _isMouseDown=false;
  	var _hasValueSet=false;
  	this.initializeValue=function(givenValue){
  		_hasValueSet=true;
  		var ratingValue=(Math.ceil(givenValue/_specificity)*100*_specificity)/100;
  		if(ratingValue>_maxRating){ratingValue=_maxRating;}else if(ratingValue<_minRating){ratingValue=_minRating;}
  		_rating=ratingValue;
  		var tableWidth=ratingValue*_BGWidth;
  		window.$("#"+ratedItem+"Filled").css({width:tableWidth});
  		if(_displayItemOverride){
  			if($("#"+_displayItemOverride)[0]){
  				if(_rating==1){
  					$("#"+_displayItemOverride).html(_rating+" "+_ratingTypeSingular);
  				}else{
  					$("#"+_displayItemOverride).html(_rating+" "+_ratingType);
  				}
  			}
  		}
  	};
  	this.resizeTable=function(event,table){
  		var ratingBarElement=$("#"+_prepend+'RatingBar')[0];
  		var tableWidth=ratingBarElement.style.width;
  		var scaleAmt=bvGetMouseX(event)-$(ratingBarElement).offset().left;
  		var ratingValue=(Math.ceil(scaleAmt/_BGWidth/_specificity)*100*_specificity)/100;
  		if(ratingValue>_maxRating){ratingValue=_maxRating;}else if(ratingValue<_minRating){ratingValue=_minRating;}
  		tableWidth=ratingValue*_BGWidth;
  		if(tableWidth<1){tableWidth=1;}
  		$("#"+table).css({width:tableWidth});
  		_rating=ratingValue;
  	};
  	this.setRating=function(event,_inputItem){
  		this.updateRating(event,_prepend+'Filled',_inputItem);
  		_hasValueSet=true;
  	};
  	this.updateRating=function(event,table,_inputItem,ignoreInput){
  		this.resizeTable(event,table);
  		if(!ignoreInput){
  			var inputItemOverrideElement=$("#"+_inputItem+_rating);
  			if(inputItemOverrideElement){
  				inputItemOverrideElement.attr('checked',true);
  			}
  		}
  		if(_displayItemOverride){
  			var displayItemOverrideElement=$("#"+_displayItemOverride)[0];
  			if(displayItemOverrideElement){
  				if(_rating==1){
  					displayItemOverrideElement.innerHTML=_rating+" "+_ratingTypeSingular;
  				}else{
  					displayItemOverrideElement.innerHTML=_rating+" "+_ratingType;
  				}
  			}
  		}
  	};
  	this.startSlide=function(){_isMouseDown=true;};
  	this.stopSlide=function(){
  		if(_isMouseDown){
  			var backgroundPath=_sparkleImage+'?i='+BvGlobalCounter.value++;
  			$("#"+_prepend+'Filled').css({background:"url("+backgroundPath+")"});
  			_isMouseDown=false;
  		}
  	};
  	this.doSlide=function(event,_inputItem){
  		_prepend = _inputItem;
  		if(_isMouseDown){
  			this.updateRating(event,_prepend+"Filled",_prepend);
  			_hasValueSet=true;
  		}else if(!_hasValueSet){
  			this.updateRating(event,_prepend+"Hover",_prepend,true);
  		}
  	};
  	this.resetHover=function(){
  		$("#"+_prepend+"Hover").css({width:1});
  		if(!_hasValueSet){
  			if(_displayItemOverride){
  				var displayItemOverrideElement=$("#"+_displayItemOverride)[0];
  				if(displayItemOverrideElement){
  					displayItemOverrideElement.innerHTML="";
  				}
  			}
  		}
  	}
  }
  </script>
  <fieldset>
      <?php if( $this->getRatings() && $this->getRatings()->getSize()): ?>
      <div class="product-review-box">
      <strong><?php echo $this->__('How do you rate this product?') ?><span class="required">*</span></strong><br />
      <span id="input-message-box"></span>
      <table class="data-table" id="product-review-table" cellspacing="0" style="display:none;">
          <thead>
              <tr>
                  <th>&nbsp;</th>
                  <th><?php echo $this->__('1 star') ?></th>
                  <th><?php echo $this->__('2 stars') ?></th>
                  <th><?php echo $this->__('3 stars') ?></th>
                  <th><?php echo $this->__('4 stars') ?></th>
                  <th><?php echo $this->__('5 stars') ?></th>
              </tr>
          </thead>
          <tbody>
          <?php $_oddIterator = 1; ?>
          <?php foreach ($this->getRatings() as $_rating): ?>
              <tr class="odd<?php if($_oddIterator == $this->getRatings()->getSize()): $_oddIterator = 0; ?> last<?php endif; ?>">
                  <td class="label"><?php echo $_rating->getRatingCode() ?></td>
              <?php $_iterator = 1; ?>
              <?php foreach ($_rating->getOptions() as $_option): ?>
                  <!--<td <?php if($_iterator == 5): ?>class="last"<?php endif; ?> style="width:60px;"><input type="radio" <?php if($_iterator == 5): $_iterator=0; ?>class="validate-one-required-by-name"<?php endif; ?> name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $_rating->getRatingCode() ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>"/></td>-->
                  <td<?php if($_iterator == 5): ?> class="last"<?php endif; ?> style="width:60px;"><input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $_rating->getRatingCode() ?>_<?php echo $_option->getValue() ?>" <?php if($_option->getValue()==4) echo 'checked="checked"';?> value="<?php echo $_option->getId() ?>" /></td>
              <?php $_iterator++ ?>
              <?php endforeach; ?>
              </tr>
          <?php $_oddIterator ++; ?>
          <?php endforeach; ?>
          </tbody>
      </table>

      <table>
        <tbody>
          <?php foreach ($this->getRatings() as $_rating): ?>
          <tr>
            <td style="text-align:left; font-weight: bold;"><?php echo $_rating->getRatingCode() ?>: </td>
            <td><div style="width:75px; cursor:pointer; background:url(<?php echo $this->getSkinUrl('images/unfilled.gif');?>) repeat; text-align:left;"	id="<?php echo $_rating->getRatingCode() ?>_RatingBar" onMouseUp="<?php echo $_rating->getRatingCode() ?>_Rating.stopSlide()" onClick="<?php echo $_rating->getRatingCode() ?>_Rating.setRating(event,'<?php echo $_rating->getRatingCode() ?>_')"	onMouseOut="<?php echo $_rating->getRatingCode() ?>_Rating.resetHover()" onMouseMove="<?php echo $_rating->getRatingCode() ?>_Rating.doSlide(event,'<?php echo $_rating->getRatingCode() ?>_')"	onMouseDown="<?php echo $_rating->getRatingCode() ?>_Rating.startSlide()">
                <div id="<?php echo $_rating->getRatingCode() ?>_Hover" style="background:transparent url(<?php echo $this->getSkinUrl('images/hover.gif');?>) repeat-x; text-align:left; height:14px;width:0px;">
                  <div style="background: transparent url(<?php echo $this->getSkinUrl('images/sparkle.gif');?>) repeat-x; height: 14px; text-align:left; width: 60px; overflow:hidden;" id="<?php echo $_rating->getRatingCode() ?>_Filled"></div>
                </div>
              </div></td>
            <td><div id="<?php echo $_rating->getRatingCode() ?>_score_title" style="margin-left:5px; font-size:11px;"></div></td>
          </tr>
          <script type="text/javascript">
          window.<?php echo $_rating->getRatingCode() ?>_Rating = new BvRatingBar('<?php echo $_rating->getRatingCode() ?>_');
          </script>
          <?php endforeach;?>
        </tbody>
      </table>

      <input type="hidden" name="validate_rating" class="validate-rating" value="" />
      <script type="text/javascript">decorateTable('product-review-table')</script>
      </div>
      <?php endif; ?>
      <div class="review-form-box">
          <?php // do not remove div - some problem whith validator in IE ?>
          <div class="review-form-box-left">
          <div>
          <label for="nickname_field"><?php echo $this->__('Nickname') ?><span class="required">*</span></label><br />
          <input class="input-text required-entry" name="nickname" id="nickname_field"  type="text" value="<?php echo $this->htmlEscape($data->getNickname()) ?>" />
          </div>

          <div>
          <label for="summary_field"><?php echo $this->__('Summary of Your Review') ?><span class="required">*</span></label><br />
          <input name="title" class="input-text  required-entry" id="summary_field"  type="text" value="<?php echo $this->htmlEscape($data->getTitle()) ?>" />
          </div>
          </div>

          <div class="review-form-box-right">
          <div>
          <label for="review_field"><?php echo $this->__('Review') ?><span class="required">*</span></label><br />
          <textarea class="required-entry txt_review" name="detail" id="review_field" cols="53" onblur="if(this.value=='') this.className='required-entry txt_review'" onfocus="this.className='required-entry'" rows="10" ><?php echo $this->htmlEscape($data->getDetail()) ?></textarea>
          </div>
          </div>
          <div class='clear'></div>
          <div >
		      <p><?php echo $this->__('Share your photoes with us');?></p>        
		      <input type='file' name='image1' class='input-text' />
		  	  <br/>
		  	  <input type='file' name='image2' class='input-text' />
		  	  <p style='font-size:12px;color:black;'><?php echo $this->__('Please only provide JPG files. Individual photo size cannot exceed 2MB.');?></p>
		  </div>
		  <div class="button-set">
              <button class="form-button button right" type="submit" style="margin-right:3px;"><span><span><?php echo $this->__('Submit Review') ?></span></span></button>
          </div>
      </div>
  </fieldset>
  </form>
</div>
<script type="text/javascript">
//<![CDATA[
    var dataForm = new VarienForm('review-form');

    Validation.addAllThese(
    [
           ['validate-rating', '<?php echo $this->__('Please select one of each of the ratings above') ?>', function(v) {
                var trs = $('product-review-table').getElementsBySelector('tr');
                var inputs;
                var error = 1;

                for( var j=0; j < trs.length; j++ ) {
                    var tr = trs[j];
                    if( j > 0 ) {
                        inputs = tr.getElementsBySelector('input');

                        for( i in inputs ) {
                            if( inputs[i].checked == true ) {
                                error = 0;
                            }
                        }

                        if( error == 1 ) {
                            return false;
                        } else {
                            error = 1;
                        }
                    }
                }
                return true;
            }]
    ]
    );
//]]>
</script>
</div>